package com.travelsky.app.Exception;

import java.io.PrintWriter;
import java.io.StringWriter;


public class BaseAppException extends Exception {

	private String messageId;

	public BaseAppException() {
	}

	public BaseAppException(Throwable cause) {
		super(cause);
	}

	public BaseAppException(String message, Throwable cause) {
		super(message, cause);
	}

	public BaseAppException(String id) {
		messageId = id;
	}

	public String getMessageId() {
		return messageId;
	}

	public void setMessageId(String id) {
		messageId = id;
	}

	public String getStackTraceString() {

		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		this.printStackTrace(pw);
		return sw.toString();
	}
	
	public String getMessage(){
		if(!"".endsWith(getMessageId()))
			return getMessageId();
		
		if(!"".equals(super.getMessage()))
			return super.getMessage();
		
		return this.toString();
	}
}
